#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2020年2月6日10:57:28
# @Author  : wangcy
# @Email   : wang_cyi@163.com
# @File    : Main.py
# -*- coding: utf-8 -*-
import logging
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By



def login_maimai() :
     
# # 1 模拟登录 
# def get_cookies() :

    logging.info("get_cookies begin ")
    # 不打开浏览器窗口
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--no-sandbox')  # 解决DevToolsActivePort文件不存在的报错
    chrome_options.add_argument('--disable-gpu')  # 谷歌文件提到需要加这个属性来规避bug
    chrome_options.add_argument('--headless')  # 无界面设置
    chrome = webdriver.Chrome(chrome_options=chrome_options) 
    

    login_url = "https://acc.maimai.cn/login"
    login_url1 = "https://acc.maimai.cn/login"
    chrome.get(login_url)
    chrome.implicitly_wait((5)
   # chrome.find_element("xpath", "//input[@class='loginPhoneInput']").send_keys(login_url1)
    
    #time.sleep(2)
    chrome.find_element("xpath", "//input[@id='login_pw']").send_keys("123456")
    chrome.find_element('xpath', "//input[@class='loginBtn']").click()
    chrome.implicitly_wait(5) 

     if u"登录" in chrome.page_source:
        cookies = chrome.get_cookies()
        with open("cookie.json", "w+")as f:
            f.write(json.dumps(cookies))
            f.close()
        logger.info("cookies succed")
    chrome.close()
def main():
    login_maimai()

if __name__ == '__main__':
    main()